/*
 * Copyright 2008 Daniel Freitas
 *
 * This file is part of Army Creator.
 * 
 * Army Creator is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Army Creator is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Army Creator.  If not, see <http://www.gnu.org/licenses/>.
 */
package cheesr.application.examples.markup;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.Model;

public class DynamicMarkup extends WebPage {

    @SuppressWarnings("serial")
    public DynamicMarkup() {
        add(new Label("hello", "Hello World (turned red on onComponentTag)!!!") {
            @Override
            protected void onComponentTag(ComponentTag tag) {
                super.onComponentTag(tag);
                tag.put("style", "color:red");
            }
        });

        add(new Label("hello2", "Hello World 2 (turned green with attribute modifiers)!!!").add(new AttributeModifier(
                "style", true, new Model("color:green"))));

        // Note: Attribute modifiers do not add together. If you add more the one attribute modifier for the same
        // attribute, the previous ones get overridden.
        add(new Link("link") {

            @Override
            public void onClick() {
                System.out.println("Link clicked");
            }
        }.add(new SimpleAttributeModifier("onclick", "return confirm('Are you sure?');")).add(
                new SimpleAttributeModifier("onclick", "return confirm('Are you really really sure?');")));

        // Note that since we are displaying only the tag body (the <span> surrounding tags will be removed from final
        // markup), the style won't be applied.
        add(new Label("renderBodyOnly", "A label without a body (note that no attribute modifiers will take"
                + " effect since the html tags were removed from the final markup)").add(
                new SimpleAttributeModifier("style", "color:brown")).setRenderBodyOnly(true));
    }
}